1
0

inbounds.html 51 KB

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