inbounds.html 52 KB

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