inbounds.html 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. .ant-col-sm-24 {
  11. margin-top: 10px;
  12. }
  13. tr.hideExpandIcon .ant-table-row-expand-icon {
  14. display: none;
  15. }
  16. </style>
  17. <body>
  18. <a-layout id="app" v-cloak>
  19. {{ template "commonSider" . }}
  20. <a-layout id="content-layout" :style="themeSwitcher.bgStyle">
  21. <a-layout-content>
  22. <a-spin :spinning="spinning" :delay="500" tip="loading">
  23. <transition name="list" appear>
  24. <a-tag v-if="false" color="red" style="margin-bottom: 10px">
  25. 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
  26. </a-tag>
  27. </transition>
  28. <transition name="list" appear>
  29. <a-card hoverable style="margin-bottom: 20px;" :class="themeSwitcher.darkCardClass">
  30. <a-row>
  31. <a-col :xs="24" :sm="24" :lg="12">
  32. {{ i18n "pages.inbounds.totalDownUp" }}:
  33. <a-tag color="green">[[ sizeFormat(total.up) ]] / [[ sizeFormat(total.down) ]]</a-tag>
  34. </a-col>
  35. <a-col :xs="24" :sm="24" :lg="12">
  36. {{ i18n "pages.inbounds.totalUsage" }}:
  37. <a-tag color="green">[[ sizeFormat(total.up + total.down) ]]</a-tag>
  38. </a-col>
  39. <a-col :xs="24" :sm="24" :lg="12">
  40. {{ i18n "pages.inbounds.inboundCount" }}:
  41. <a-tag color="green">[[ dbInbounds.length ]]</a-tag>
  42. </a-col>
  43. <a-col :xs="24" :sm="24" :lg="12">
  44. {{ i18n "clients" }}:
  45. <a-tag color="green">[[ total.clients ]]</a-tag>
  46. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.darkClass">
  47. <template slot="content">
  48. <p v-for="clientEmail in total.deactive">[[ clientEmail ]]</p>
  49. </template>
  50. <a-tag v-if="total.deactive.length">[[ total.deactive.length ]]</a-tag>
  51. </a-popover>
  52. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.darkClass">
  53. <template slot="content">
  54. <p v-for="clientEmail in total.depleted">[[ clientEmail ]]</p>
  55. </template>
  56. <a-tag color="red" v-if="total.depleted.length">[[ total.depleted.length ]]</a-tag>
  57. </a-popover>
  58. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.darkClass">
  59. <template slot="content">
  60. <p v-for="clientEmail in total.expiring">[[ clientEmail ]]</p>
  61. </template>
  62. <a-tag color="orange" v-if="total.expiring.length">[[ total.expiring.length ]]</a-tag>
  63. </a-popover>
  64. </a-col>
  65. </a-row>
  66. </a-card>
  67. </transition>
  68. <transition name="list" appear>
  69. <a-card hoverable :class="themeSwitcher.darkCardClass">
  70. <div slot="title">
  71. <a-row>
  72. <a-col :xs="24" :sm="24" :lg="12">
  73. <a-button type="primary" icon="plus" @click="openAddInbound">{{ i18n "pages.inbounds.addInbound" }}</a-button>
  74. <a-dropdown :trigger="['click']">
  75. <a-button type="primary" icon="menu">{{ i18n "pages.inbounds.generalActions" }}</a-button>
  76. <a-menu slot="overlay" @click="a => generalActions(a)" :theme="themeSwitcher.currentTheme">
  77. <a-menu-item key="export">
  78. <a-icon type="export"></a-icon>
  79. {{ i18n "pages.inbounds.export" }}
  80. </a-menu-item>
  81. <a-menu-item key="resetInbounds">
  82. <a-icon type="reload"></a-icon>
  83. {{ i18n "pages.inbounds.resetAllTraffic" }}
  84. </a-menu-item>
  85. <a-menu-item key="resetClients">
  86. <a-icon type="file-done"></a-icon>
  87. {{ i18n "pages.inbounds.resetAllClientTraffics" }}
  88. </a-menu-item>
  89. <a-menu-item key="delDepletedClients">
  90. <a-icon type="rest"></a-icon>
  91. {{ i18n "pages.inbounds.delDepletedClients" }}
  92. </a-menu-item>
  93. </a-menu>
  94. </a-dropdown>
  95. </a-col>
  96. <a-col :xs="24" :sm="24" :lg="12" style="text-align: right;">
  97. <a-select v-model="refreshInterval"
  98. style="width: 65px;"
  99. v-if="isRefreshEnabled"
  100. @change="changeRefreshInterval"
  101. :dropdown-class-name="themeSwitcher.darkCardClass">
  102. <a-select-option v-for="key in [5,10,30,60]" :value="key*1000">[[ key ]]s</a-select-option>
  103. </a-select>
  104. <a-icon type="sync" :spin="refreshing" @click="manualRefresh" style="margin: 0 5px;"></a-icon>
  105. <a-switch v-model="isRefreshEnabled" @change="toggleRefresh"></a-switch>
  106. </a-col>
  107. </a-row>
  108. </div>
  109. <a-switch v-model="enableFilter"
  110. checked-children='{{ i18n "search" }}' un-checked-children='{{ i18n "filter" }}'
  111. @change="toggleFilter" style="margin-right: 10px;">
  112. </a-switch>
  113. <a-input v-if="!enableFilter" v-model.lazy="searchKey" placeholder='{{ i18n "search" }}' autofocus style="max-width: 300px"></a-input>
  114. <a-radio-group v-if="enableFilter" v-model="filterBy" @change="filterInbounds" button-style="solid">
  115. <a-radio-button value="">{{ i18n "none" }}</a-radio-button>
  116. <a-radio-button value="deactive">{{ i18n "disabled" }}</a-radio-button>
  117. <a-radio-button value="depleted">{{ i18n "depleted" }}</a-radio-button>
  118. <a-radio-button value="expiring">{{ i18n "depletingSoon" }}</a-radio-button>
  119. </a-radio-group>
  120. <a-table :columns="columns" :row-key="dbInbound => dbInbound.id"
  121. :data-source="searchedInbounds"
  122. :loading="spinning" :scroll="{ x: 1200 }"
  123. :pagination="false"
  124. :expand-icon-as-cell="false"
  125. :expand-row-by-click="false"
  126. :expand-icon-column-index="0"
  127. :row-class-name="dbInbound => (dbInbound.isTrojan || dbInbound.isVLess || dbInbound.isVMess || (dbInbound.isSS && dbInbound.toInbound().isSSMultiUser) ? '' : 'hideExpandIcon')"
  128. style="margin-top: 20px"
  129. @change="() => getDBInbounds()">
  130. <template slot="action" slot-scope="text, dbInbound">
  131. <a-icon type="edit" style="font-size: 22px" @click="openEditInbound(dbInbound.id);"></a-icon>
  132. <a-dropdown :trigger="['click']">
  133. <a @click="e => e.preventDefault()">{{ i18n "pages.inbounds.operate" }}</a>
  134. <a-menu slot="overlay" @click="a => clickAction(a, dbInbound)" :theme="themeSwitcher.currentTheme">
  135. <a-menu-item key="edit">
  136. <a-icon type="edit"></a-icon>
  137. {{ i18n "edit" }}
  138. </a-menu-item>
  139. <a-menu-item key="qrcode" v-if="dbInbound.isSS && !dbInbound.toInbound().isSSMultiUser">
  140. <a-icon type="qrcode"></a-icon>
  141. {{ i18n "qrCode" }}
  142. </a-menu-item>
  143. <template v-if="dbInbound.isTrojan || dbInbound.isVLess || dbInbound.isVMess || (dbInbound.isSS && dbInbound.toInbound().isSSMultiUser)">
  144. <a-menu-item key="addClient">
  145. <a-icon type="user-add"></a-icon>
  146. {{ i18n "pages.client.add"}}
  147. </a-menu-item>
  148. <a-menu-item key="addBulkClient">
  149. <a-icon type="usergroup-add"></a-icon>
  150. {{ i18n "pages.client.bulk"}}
  151. </a-menu-item>
  152. <a-menu-item key="resetClients">
  153. <a-icon type="file-done"></a-icon>
  154. {{ i18n "pages.inbounds.resetInboundClientTraffics"}}
  155. </a-menu-item>
  156. <a-menu-item key="export">
  157. <a-icon type="export"></a-icon>
  158. {{ i18n "pages.inbounds.export"}}
  159. </a-menu-item>
  160. <a-menu-item key="delDepletedClients">
  161. <a-icon type="rest"></a-icon>
  162. {{ i18n "pages.inbounds.delDepletedClients" }}
  163. </a-menu-item>
  164. </template>
  165. <template v-else>
  166. <a-menu-item key="showInfo">
  167. <a-icon type="info-circle"></a-icon>
  168. {{ i18n "info"}}
  169. </a-menu-item>
  170. </template>
  171. <a-menu-item key="resetTraffic">
  172. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  173. </a-menu-item>
  174. <a-menu-item key="clone">
  175. <a-icon type="block"></a-icon> {{ i18n "pages.inbounds.clone"}}
  176. </a-menu-item>
  177. <a-menu-item key="delete">
  178. <span style="color: #FF4D4F">
  179. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  180. </span>
  181. </a-menu-item>
  182. </a-menu>
  183. </a-dropdown>
  184. </template>
  185. <template slot="protocol" slot-scope="text, dbInbound">
  186. <a-tag style="margin:0;" color="blue">[[ dbInbound.protocol ]]</a-tag>
  187. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  188. <a-tag style="margin:0;" color="green">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  189. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isTls" color="cyan">TLS</a-tag>
  190. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isXtls" color="cyan">XTLS</a-tag>
  191. <a-tag style="margin:0;" v-if="dbInbound.toInbound().stream.isReality" color="cyan">Reality</a-tag>
  192. </template>
  193. </template>
  194. <template slot="clients" slot-scope="text, dbInbound">
  195. <template v-if="clientCount[dbInbound.id]">
  196. <a-tag style="margin:0;" color="green">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  197. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.darkClass">
  198. <template slot="content">
  199. <p v-for="clientEmail in clientCount[dbInbound.id].deactive">[[ clientEmail ]]</p>
  200. </template>
  201. <a-tag style="margin:0; padding: 0 2px;" v-if="clientCount[dbInbound.id].deactive.length">[[ clientCount[dbInbound.id].deactive.length ]]</a-tag>
  202. </a-popover>
  203. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.darkClass">
  204. <template slot="content">
  205. <p v-for="clientEmail in clientCount[dbInbound.id].depleted">[[ clientEmail ]]</p>
  206. </template>
  207. <a-tag style="margin:0; padding: 0 2px;" color="red" v-if="clientCount[dbInbound.id].depleted.length">[[ clientCount[dbInbound.id].depleted.length ]]</a-tag>
  208. </a-popover>
  209. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.darkClass">
  210. <template slot="content">
  211. <p v-for="clientEmail in clientCount[dbInbound.id].expiring">[[ clientEmail ]]</p>
  212. </template>
  213. <a-tag style="margin:0; padding: 0 2px;" color="orange" v-if="clientCount[dbInbound.id].expiring.length">[[ clientCount[dbInbound.id].expiring.length ]]</a-tag>
  214. </a-popover>
  215. </template>
  216. </template>
  217. <template slot="traffic" slot-scope="text, dbInbound">
  218. <a-popover :overlay-class-name="themeSwitcher.darkClass">
  219. <template slot="content">
  220. <table cellpadding="2" width="100%">
  221. <tr>
  222. <td>↑[[ sizeFormat(dbInbound.up) ]]</td>
  223. <td>↓[[ sizeFormat(dbInbound.down) ]]</td>
  224. </tr>
  225. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  226. <td>{{ i18n "remained" }}</td>
  227. <td>[[ sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  228. </tr>
  229. </table>
  230. </template>
  231. <a-tag :color="dbInbound.total == 0 ? 'green' : dbInbound.up + dbInbound.down < dbInbound.total ? 'cyan' : 'red'">
  232. [[ sizeFormat(dbInbound.up + dbInbound.down) ]] /
  233. <template v-if="dbInbound.total > 0">
  234. [[ sizeFormat(dbInbound.total) ]]
  235. </template>
  236. <template v-else>
  237. <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>
  238. </template>
  239. </a-tag>
  240. </a-popover>
  241. </template>
  242. <template slot="enable" slot-scope="text, dbInbound">
  243. <a-switch v-model="dbInbound.enable" @change="switchEnable(dbInbound.id)"></a-switch>
  244. </template>
  245. <template slot="expiryTime" slot-scope="text, dbInbound">
  246. <template v-if="dbInbound.expiryTime > 0">
  247. <a-tag v-if="dbInbound.isExpiry" color="red">
  248. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  249. </a-tag>
  250. <a-tag v-else color="blue">
  251. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  252. </a-tag>
  253. </template>
  254. <a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
  255. </template>
  256. <template slot="expandedRowRender" slot-scope="record">
  257. <a-table
  258. v-if="(record.protocol === Protocols.VLESS) || (record.protocol === Protocols.VMESS)"
  259. :row-key="client => client.id"
  260. :columns="innerColumns"
  261. :data-source="getInboundClients(record)"
  262. :pagination="false"
  263. style="margin-left: 20px;"
  264. >
  265. {{template "client_table"}}
  266. </a-table>
  267. <a-table
  268. v-else-if="record.protocol === Protocols.TROJAN || record.toInbound().isSSMultiUser"
  269. :row-key="client => client.id"
  270. :columns="innerTrojanColumns"
  271. :data-source="getInboundClients(record)"
  272. :pagination="false"
  273. style="margin-left: 20px;"
  274. >
  275. {{template "client_table"}}
  276. </a-table>
  277. </template>
  278. </a-table>
  279. </a-card>
  280. </transition>
  281. </a-spin>
  282. </a-layout-content>
  283. </a-layout>
  284. </a-layout>
  285. {{template "js" .}}
  286. {{template "component/themeSwitcher" .}}
  287. <script>
  288. const columns = [{
  289. title: "ID",
  290. align: 'right',
  291. dataIndex: "id",
  292. width: 30,
  293. }, {
  294. title: '{{ i18n "pages.inbounds.operate" }}',
  295. align: 'center',
  296. width: 40,
  297. scopedSlots: { customRender: 'action' },
  298. }, {
  299. title: '{{ i18n "pages.inbounds.enable" }}',
  300. align: 'center',
  301. width: 40,
  302. scopedSlots: { customRender: 'enable' },
  303. }, {
  304. title: '{{ i18n "pages.inbounds.remark" }}',
  305. align: 'center',
  306. width: 80,
  307. dataIndex: "remark",
  308. }, {
  309. title: '{{ i18n "pages.inbounds.port" }}',
  310. align: 'center',
  311. dataIndex: "port",
  312. width: 40,
  313. }, {
  314. title: '{{ i18n "pages.inbounds.protocol" }}',
  315. align: 'left',
  316. width: 90,
  317. scopedSlots: { customRender: 'protocol' },
  318. }, {
  319. title: '{{ i18n "clients" }}',
  320. align: 'left',
  321. width: 40,
  322. scopedSlots: { customRender: 'clients' },
  323. }, {
  324. title: '{{ i18n "pages.inbounds.traffic" }}',
  325. align: 'center',
  326. width: 60,
  327. scopedSlots: { customRender: 'traffic' },
  328. }, {
  329. title: '{{ i18n "pages.inbounds.expireDate" }}',
  330. align: 'center',
  331. width: 80,
  332. scopedSlots: { customRender: 'expiryTime' },
  333. }];
  334. const innerColumns = [
  335. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  336. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  337. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  338. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 50, scopedSlots: { customRender: 'traffic' } },
  339. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 50, scopedSlots: { customRender: 'expiryTime' } },
  340. { title: 'UUID', width: 120, dataIndex: "id" },
  341. ];
  342. const innerTrojanColumns = [
  343. { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } },
  344. { title: '{{ i18n "pages.inbounds.enable" }}', width: 40, scopedSlots: { customRender: 'enable' } },
  345. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  346. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 50, scopedSlots: { customRender: 'traffic' } },
  347. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 50, scopedSlots: { customRender: 'expiryTime' } },
  348. { title: '{{ i18n "password" }}', width: 170, dataIndex: "password" },
  349. ];
  350. const app = new Vue({
  351. delimiters: ['[[', ']]'],
  352. el: '#app',
  353. data: {
  354. siderDrawer,
  355. themeSwitcher,
  356. spinning: false,
  357. inbounds: [],
  358. dbInbounds: [],
  359. searchKey: '',
  360. enableFilter: false,
  361. filterBy: '',
  362. searchedInbounds: [],
  363. expireDiff: 0,
  364. trafficDiff: 0,
  365. defaultCert: '',
  366. defaultKey: '',
  367. clientCount: [],
  368. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  369. refreshing: false,
  370. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  371. subSettings: {
  372. enable : false,
  373. port: 0,
  374. path: '',
  375. domain: '',
  376. tls: false
  377. },
  378. tgBotEnable: false
  379. },
  380. methods: {
  381. loading(spinning = true) {
  382. this.spinning = spinning;
  383. },
  384. async getDBInbounds() {
  385. this.refreshing = true;
  386. const msg = await HttpUtil.post('/panel/inbound/list');
  387. if (!msg.success) {
  388. this.refreshing = false;
  389. return;
  390. }
  391. this.setInbounds(msg.obj);
  392. setTimeout(() => {
  393. this.refreshing = false;
  394. }, 500);
  395. },
  396. async getDefaultSettings() {
  397. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  398. if (!msg.success) {
  399. return;
  400. }
  401. with(msg.obj){
  402. this.expireDiff = expireDiff * 86400000;
  403. this.trafficDiff = trafficDiff * 1073741824;
  404. this.defaultCert = defaultCert;
  405. this.defaultKey = defaultKey;
  406. this.tgBotEnable = tgBotEnable;
  407. this.subSettings = {
  408. enable : subEnable,
  409. port: subPort,
  410. path: subPath,
  411. domain: subDomain,
  412. tls: subTLS
  413. };
  414. }
  415. },
  416. setInbounds(dbInbounds) {
  417. this.inbounds.splice(0);
  418. this.dbInbounds.splice(0);
  419. this.clientCount.splice(0);
  420. for (const inbound of dbInbounds) {
  421. const dbInbound = new DBInbound(inbound);
  422. to_inbound = dbInbound.toInbound()
  423. this.inbounds.push(to_inbound);
  424. this.dbInbounds.push(dbInbound);
  425. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  426. if (inbound.protocol === Protocols.SHADOWSOCKS && (!to_inbound.isSSMultiUser)) {
  427. continue;
  428. }
  429. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  430. }
  431. }
  432. if(this.enableFilter){
  433. this.filterInbounds();
  434. } else {
  435. this.searchInbounds(this.searchKey);
  436. }
  437. },
  438. getClientCounts(dbInbound, inbound) {
  439. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [];
  440. clients = this.getClients(dbInbound.protocol, inbound.settings);
  441. clientStats = dbInbound.clientStats
  442. now = new Date().getTime()
  443. if (clients) {
  444. clientCount = clients.length;
  445. if (dbInbound.enable) {
  446. clients.forEach(client => {
  447. client.enable ? active.push(client.email) : deactive.push(client.email);
  448. });
  449. clientStats.forEach(client => {
  450. if (!client.enable) {
  451. depleted.push(client.email);
  452. } else {
  453. if ((client.expiryTime > 0 && (client.expiryTime - now < this.expireDiff)) ||
  454. (client.total > 0 && (client.total - (client.up + client.down) < this.trafficDiff))) expiring.push(client.email);
  455. }
  456. });
  457. } else {
  458. clients.forEach(client => {
  459. deactive.push(client.email);
  460. });
  461. }
  462. }
  463. return {
  464. clients: clientCount,
  465. active: active,
  466. deactive: deactive,
  467. depleted: depleted,
  468. expiring: expiring,
  469. };
  470. },
  471. searchInbounds(key) {
  472. if (ObjectUtil.isEmpty(key)) {
  473. this.searchedInbounds = this.dbInbounds.slice();
  474. } else {
  475. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  476. this.dbInbounds.forEach(inbound => {
  477. if (ObjectUtil.deepSearch(inbound, key)) {
  478. const newInbound = new DBInbound(inbound);
  479. const inboundSettings = JSON.parse(inbound.settings);
  480. if (inboundSettings.hasOwnProperty('clients')) {
  481. const searchedSettings = { "clients": [] };
  482. inboundSettings.clients.forEach(client => {
  483. if (ObjectUtil.deepSearch(client, key)) {
  484. searchedSettings.clients.push(client);
  485. }
  486. });
  487. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  488. }
  489. this.searchedInbounds.push(newInbound);
  490. }
  491. });
  492. }
  493. },
  494. filterInbounds() {
  495. if (ObjectUtil.isEmpty(this.filterBy)) {
  496. this.searchedInbounds = this.dbInbounds.slice();
  497. } else {
  498. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  499. this.dbInbounds.forEach(inbound => {
  500. const newInbound = new DBInbound(inbound);
  501. const inboundSettings = JSON.parse(inbound.settings);
  502. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)){
  503. const list = this.clientCount[inbound.id][this.filterBy];
  504. if (list.length > 0) {
  505. const filteredSettings = { "clients": [] };
  506. inboundSettings.clients.forEach(client => {
  507. if (list.includes(client.email)) {
  508. filteredSettings.clients.push(client);
  509. }
  510. });
  511. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  512. this.searchedInbounds.push(newInbound);
  513. }
  514. }
  515. });
  516. }
  517. },
  518. toggleFilter(){
  519. if(this.enableFilter) {
  520. this.searchKey = '';
  521. } else {
  522. this.filterBy = '';
  523. this.searchedInbounds = this.dbInbounds.slice();
  524. }
  525. },
  526. generalActions(action) {
  527. switch (action.key) {
  528. case "export":
  529. this.exportAllLinks();
  530. break;
  531. case "resetInbounds":
  532. this.resetAllTraffic();
  533. break;
  534. case "resetClients":
  535. this.resetAllClientTraffics(-1);
  536. break;
  537. case "delDepletedClients":
  538. this.delDepletedClients(-1)
  539. break;
  540. }
  541. },
  542. clickAction(action, dbInbound) {
  543. switch (action.key) {
  544. case "qrcode":
  545. this.showQrcode(dbInbound);
  546. break;
  547. case "showInfo":
  548. this.showInfo(dbInbound);
  549. break;
  550. case "edit":
  551. this.openEditInbound(dbInbound.id);
  552. break;
  553. case "addClient":
  554. this.openAddClient(dbInbound.id)
  555. break;
  556. case "addBulkClient":
  557. this.openAddBulkClient(dbInbound.id)
  558. break;
  559. case "export":
  560. this.inboundLinks(dbInbound.id);
  561. break;
  562. case "resetTraffic":
  563. this.resetTraffic(dbInbound.id);
  564. break;
  565. case "resetClients":
  566. this.resetAllClientTraffics(dbInbound.id);
  567. break;
  568. case "clone":
  569. this.openCloneInbound(dbInbound);
  570. break;
  571. case "delete":
  572. this.delInbound(dbInbound.id);
  573. break;
  574. case "delDepletedClients":
  575. this.delDepletedClients(dbInbound.id)
  576. break;
  577. }
  578. },
  579. openCloneInbound(dbInbound) {
  580. this.$confirm({
  581. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  582. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  583. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  584. cancelText: '{{ i18n "cancel" }}',
  585. onOk: () => {
  586. const baseInbound = dbInbound.toInbound();
  587. dbInbound.up = 0;
  588. dbInbound.down = 0;
  589. this.cloneInbound(baseInbound, dbInbound);
  590. },
  591. });
  592. },
  593. async cloneInbound(baseInbound, dbInbound) {
  594. const data = {
  595. up: dbInbound.up,
  596. down: dbInbound.down,
  597. total: dbInbound.total,
  598. remark: dbInbound.remark + " - Cloned",
  599. enable: dbInbound.enable,
  600. expiryTime: dbInbound.expiryTime,
  601. listen: '',
  602. port: RandomUtil.randomIntRange(10000, 60000),
  603. protocol: baseInbound.protocol,
  604. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  605. streamSettings: baseInbound.stream.toString(),
  606. sniffing: baseInbound.canSniffing() ? baseInbound.sniffing.toString() : '{}',
  607. };
  608. await this.submit('/panel/inbound/add', data, inModal);
  609. },
  610. openAddInbound() {
  611. inModal.show({
  612. title: '{{ i18n "pages.inbounds.addInbound"}}',
  613. okText: '{{ i18n "pages.inbounds.create"}}',
  614. cancelText: '{{ i18n "close" }}',
  615. confirm: async (inbound, dbInbound) => {
  616. inModal.loading();
  617. await this.addInbound(inbound, dbInbound);
  618. inModal.close();
  619. },
  620. isEdit: false
  621. });
  622. },
  623. openEditInbound(dbInboundId) {
  624. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  625. const inbound = dbInbound.toInbound();
  626. inModal.show({
  627. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  628. okText: '{{ i18n "pages.inbounds.update"}}',
  629. cancelText: '{{ i18n "close" }}',
  630. inbound: inbound,
  631. dbInbound: dbInbound,
  632. confirm: async (inbound, dbInbound) => {
  633. inModal.loading();
  634. await this.updateInbound(inbound, dbInbound);
  635. inModal.close();
  636. },
  637. isEdit: true
  638. });
  639. },
  640. async addInbound(inbound, dbInbound) {
  641. const data = {
  642. up: dbInbound.up,
  643. down: dbInbound.down,
  644. total: dbInbound.total,
  645. remark: dbInbound.remark,
  646. enable: dbInbound.enable,
  647. expiryTime: dbInbound.expiryTime,
  648. listen: inbound.listen,
  649. port: inbound.port,
  650. protocol: inbound.protocol,
  651. settings: inbound.settings.toString(),
  652. };
  653. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  654. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  655. await this.submit('/panel/inbound/add', data, inModal);
  656. },
  657. async updateInbound(inbound, dbInbound) {
  658. const data = {
  659. up: dbInbound.up,
  660. down: dbInbound.down,
  661. total: dbInbound.total,
  662. remark: dbInbound.remark,
  663. enable: dbInbound.enable,
  664. expiryTime: dbInbound.expiryTime,
  665. listen: inbound.listen,
  666. port: inbound.port,
  667. protocol: inbound.protocol,
  668. settings: inbound.settings.toString(),
  669. };
  670. if (inbound.canEnableStream()) data.streamSettings = inbound.stream.toString();
  671. if (inbound.canSniffing()) data.sniffing = inbound.sniffing.toString();
  672. await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal);
  673. },
  674. openAddClient(dbInboundId) {
  675. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  676. clientModal.show({
  677. title: '{{ i18n "pages.client.add"}}',
  678. okText: '{{ i18n "pages.client.submitAdd"}}',
  679. dbInbound: dbInbound,
  680. confirm: async (clients, dbInboundId) => {
  681. clientModal.loading();
  682. await this.addClient(clients, dbInboundId);
  683. clientModal.close();
  684. },
  685. isEdit: false
  686. });
  687. },
  688. openAddBulkClient(dbInboundId) {
  689. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  690. clientsBulkModal.show({
  691. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  692. okText: '{{ i18n "pages.client.bulk"}}',
  693. dbInbound: dbInbound,
  694. confirm: async (clients, dbInboundId) => {
  695. clientsBulkModal.loading();
  696. await this.addClient(clients, dbInboundId);
  697. clientsBulkModal.close();
  698. },
  699. });
  700. },
  701. openEditClient(dbInboundId, client) {
  702. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  703. clients = this.getInboundClients(dbInbound);
  704. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  705. clientModal.show({
  706. title: '{{ i18n "pages.client.edit"}}',
  707. okText: '{{ i18n "pages.client.submitEdit"}}',
  708. dbInbound: dbInbound,
  709. index: index,
  710. confirm: async (client, dbInboundId, clientId) => {
  711. clientModal.loading();
  712. await this.updateClient(client, dbInboundId, clientId);
  713. clientModal.close();
  714. },
  715. isEdit: true
  716. });
  717. },
  718. findIndexOfClient(protocol, clients, client) {
  719. switch (protocol) {
  720. case Protocols.TROJAN:
  721. case Protocols.SHADOWSOCKS:
  722. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  723. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  724. }
  725. },
  726. async addClient(clients, dbInboundId) {
  727. const data = {
  728. id: dbInboundId,
  729. settings: '{"clients": [' + clients.toString() + ']}',
  730. };
  731. await this.submit(`/panel/inbound/addClient`, data);
  732. },
  733. async updateClient(client, dbInboundId, clientId) {
  734. const data = {
  735. id: dbInboundId,
  736. settings: '{"clients": [' + client.toString() + ']}',
  737. };
  738. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  739. },
  740. resetTraffic(dbInboundId) {
  741. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  742. this.$confirm({
  743. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  744. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  745. class: themeSwitcher.darkCardClass,
  746. okText: '{{ i18n "reset"}}',
  747. cancelText: '{{ i18n "cancel"}}',
  748. onOk: () => {
  749. const inbound = dbInbound.toInbound();
  750. dbInbound.up = 0;
  751. dbInbound.down = 0;
  752. this.updateInbound(inbound, dbInbound);
  753. },
  754. });
  755. },
  756. delInbound(dbInboundId) {
  757. this.$confirm({
  758. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  759. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  760. class: themeSwitcher.darkCardClass,
  761. okText: '{{ i18n "delete"}}',
  762. cancelText: '{{ i18n "cancel"}}',
  763. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  764. });
  765. },
  766. delClient(dbInboundId, client) {
  767. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  768. clientId = this.getClientId(dbInbound.protocol, client);
  769. this.$confirm({
  770. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  771. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  772. class: themeSwitcher.darkCardClass,
  773. okText: '{{ i18n "delete"}}',
  774. cancelText: '{{ i18n "cancel"}}',
  775. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  776. });
  777. },
  778. getClients(protocol, clientSettings) {
  779. switch (protocol) {
  780. case Protocols.VMESS: return clientSettings.vmesses;
  781. case Protocols.VLESS: return clientSettings.vlesses;
  782. case Protocols.TROJAN: return clientSettings.trojans;
  783. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  784. default: return null;
  785. }
  786. },
  787. getClientId(protocol, client) {
  788. switch (protocol) {
  789. case Protocols.TROJAN: return client.password;
  790. case Protocols.SHADOWSOCKS: return client.email;
  791. default: return client.id;
  792. }
  793. },
  794. checkFallback(dbInbound) {
  795. newDbInbound = new DBInbound(dbInbound);
  796. if (dbInbound.listen.startsWith("@")){
  797. rootInbound = this.inbounds.find((i) =>
  798. i.tls &&
  799. ['trojan','vless'].includes(i.protocol) &&
  800. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  801. );
  802. if (rootInbound) {
  803. newDbInbound.listen = rootInbound.listen;
  804. newDbInbound.port = rootInbound.port;
  805. newInbound = newDbInbound.toInbound();
  806. newInbound.stream.security = 'tls';
  807. newInbound.stream.tls = rootInbound.stream.tls;
  808. newDbInbound.streamSettings = newInbound.stream.toString();
  809. }
  810. }
  811. return newDbInbound;
  812. },
  813. showQrcode(dbInbound, clientIndex) {
  814. newDbInbound = this.checkFallback(dbInbound);
  815. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, clientIndex);
  816. },
  817. showInfo(dbInbound, index) {
  818. newDbInbound = this.checkFallback(dbInbound);
  819. infoModal.show(newDbInbound, index);
  820. },
  821. switchEnable(dbInboundId) {
  822. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  823. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  824. },
  825. async switchEnableClient(dbInboundId, client) {
  826. this.loading()
  827. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  828. inbound = dbInbound.toInbound();
  829. clients = this.getClients(dbInbound.protocol, inbound.settings);
  830. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  831. clients[index].enable = !clients[index].enable;
  832. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  833. await this.updateClient(clients[index], dbInboundId, clientId);
  834. this.loading(false);
  835. },
  836. async submit(url, data) {
  837. const msg = await HttpUtil.postWithModal(url, data);
  838. if (msg.success) {
  839. await this.getDBInbounds();
  840. }
  841. },
  842. getInboundClients(dbInbound) {
  843. if (dbInbound.protocol == Protocols.VLESS) {
  844. return dbInbound.toInbound().settings.vlesses;
  845. } else if (dbInbound.protocol == Protocols.VMESS) {
  846. return dbInbound.toInbound().settings.vmesses;
  847. } else if (dbInbound.protocol == Protocols.TROJAN) {
  848. return dbInbound.toInbound().settings.trojans;
  849. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  850. return dbInbound.toInbound().settings.shadowsockses;
  851. }
  852. },
  853. resetClientTraffic(client, dbInboundId) {
  854. this.$confirm({
  855. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  856. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  857. class: themeSwitcher.darkCardClass,
  858. okText: '{{ i18n "reset"}}',
  859. cancelText: '{{ i18n "cancel"}}',
  860. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  861. })
  862. },
  863. resetAllTraffic() {
  864. this.$confirm({
  865. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  866. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  867. class: themeSwitcher.darkCardClass,
  868. okText: '{{ i18n "reset"}}',
  869. cancelText: '{{ i18n "cancel"}}',
  870. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  871. });
  872. },
  873. resetAllClientTraffics(dbInboundId) {
  874. this.$confirm({
  875. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  876. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  877. class: themeSwitcher.darkCardClass,
  878. okText: '{{ i18n "reset"}}',
  879. cancelText: '{{ i18n "cancel"}}',
  880. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  881. })
  882. },
  883. delDepletedClients(dbInboundId) {
  884. this.$confirm({
  885. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  886. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  887. class: themeSwitcher.darkCardClass,
  888. okText: '{{ i18n "reset"}}',
  889. cancelText: '{{ i18n "cancel"}}',
  890. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  891. })
  892. },
  893. isExpiry(dbInbound, index) {
  894. return dbInbound.toInbound().isExpiry(index)
  895. },
  896. getUpStats(dbInbound, email) {
  897. if (email.length == 0) return 0
  898. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  899. return clientStats ? clientStats.up : 0
  900. },
  901. getDownStats(dbInbound, email) {
  902. if (email.length == 0) return 0
  903. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  904. return clientStats ? clientStats.down : 0
  905. },
  906. statsColor(dbInbound, email) {
  907. if(email.length == 0) return 'blue';
  908. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  909. return usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  910. },
  911. isClientEnabled(dbInbound, email) {
  912. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  913. return clientStats ? clientStats['enable'] : true
  914. },
  915. isRemovable(dbInbound_id) {
  916. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  917. },
  918. inboundLinks(dbInboundId) {
  919. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  920. newDbInbound = this.checkFallback(dbInbound);
  921. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks, newDbInbound.remark);
  922. },
  923. exportAllLinks() {
  924. let copyText = '';
  925. for (const dbInbound of this.dbInbounds) {
  926. copyText += dbInbound.genInboundLinks
  927. }
  928. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  929. },
  930. async startDataRefreshLoop() {
  931. while (this.isRefreshEnabled) {
  932. try {
  933. await this.getDBInbounds();
  934. } catch (e) {
  935. console.error(e);
  936. }
  937. await PromiseUtil.sleep(this.refreshInterval);
  938. }
  939. },
  940. toggleRefresh() {
  941. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  942. if (this.isRefreshEnabled) {
  943. this.startDataRefreshLoop();
  944. }
  945. },
  946. changeRefreshInterval() {
  947. localStorage.setItem("refreshInterval", this.refreshInterval);
  948. },
  949. async manualRefresh() {
  950. if (!this.refreshing) {
  951. this.spinning = true;
  952. await this.getDBInbounds();
  953. this.spinning = false;
  954. }
  955. },
  956. },
  957. watch: {
  958. searchKey: debounce(function (newVal) {
  959. this.searchInbounds(newVal);
  960. }, 500)
  961. },
  962. mounted() {
  963. this.loading();
  964. this.getDefaultSettings();
  965. if (this.isRefreshEnabled) {
  966. this.startDataRefreshLoop();
  967. }
  968. else {
  969. this.getDBInbounds();
  970. }
  971. this.loading(false);
  972. },
  973. computed: {
  974. total() {
  975. let down = 0, up = 0;
  976. let clients = 0, deactive = [], depleted = [], expiring = [];
  977. this.dbInbounds.forEach(dbInbound => {
  978. down += dbInbound.down;
  979. up += dbInbound.up;
  980. if (this.clientCount[dbInbound.id]) {
  981. clients += this.clientCount[dbInbound.id].clients;
  982. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  983. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  984. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  985. }
  986. });
  987. return {
  988. down: down,
  989. up: up,
  990. clients: clients,
  991. deactive: deactive,
  992. depleted: depleted,
  993. expiring: expiring,
  994. };
  995. }
  996. },
  997. });
  998. </script>
  999. {{template "inboundModal"}}
  1000. {{template "promptModal"}}
  1001. {{template "qrcodeModal"}}
  1002. {{template "textModal"}}
  1003. {{template "inboundInfoModal"}}
  1004. {{template "clientsModal"}}
  1005. {{template "clientsBulkModal"}}
  1006. </body>
  1007. </html>