inbounds.html 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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(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(clients, client) {
  719. firstKey = Object.keys(client)[0];
  720. return clients.findIndex(c => c[firstKey] === client[firstKey]);
  721. },
  722. async addClient(clients, dbInboundId) {
  723. const data = {
  724. id: dbInboundId,
  725. settings: '{"clients": [' + clients.toString() + ']}',
  726. };
  727. await this.submit(`/panel/inbound/addClient`, data);
  728. },
  729. async updateClient(client, dbInboundId, clientId) {
  730. const data = {
  731. id: dbInboundId,
  732. settings: '{"clients": [' + client.toString() + ']}',
  733. };
  734. await this.submit(`/panel/inbound/updateClient/${clientId}`, data);
  735. },
  736. resetTraffic(dbInboundId) {
  737. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  738. this.$confirm({
  739. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  740. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  741. class: themeSwitcher.darkCardClass,
  742. okText: '{{ i18n "reset"}}',
  743. cancelText: '{{ i18n "cancel"}}',
  744. onOk: () => {
  745. const inbound = dbInbound.toInbound();
  746. dbInbound.up = 0;
  747. dbInbound.down = 0;
  748. this.updateInbound(inbound, dbInbound);
  749. },
  750. });
  751. },
  752. delInbound(dbInboundId) {
  753. this.$confirm({
  754. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  755. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  756. class: themeSwitcher.darkCardClass,
  757. okText: '{{ i18n "delete"}}',
  758. cancelText: '{{ i18n "cancel"}}',
  759. onOk: () => this.submit('/panel/inbound/del/' + dbInboundId),
  760. });
  761. },
  762. delClient(dbInboundId, client) {
  763. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  764. clientId = this.getClientId(dbInbound.protocol, client);
  765. this.$confirm({
  766. title: '{{ i18n "pages.inbounds.deleteInbound"}}',
  767. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  768. class: themeSwitcher.darkCardClass,
  769. okText: '{{ i18n "delete"}}',
  770. cancelText: '{{ i18n "cancel"}}',
  771. onOk: () => this.submit(`/panel/inbound/${dbInboundId}/delClient/${clientId}`),
  772. });
  773. },
  774. getClients(protocol, clientSettings) {
  775. switch (protocol) {
  776. case Protocols.VMESS: return clientSettings.vmesses;
  777. case Protocols.VLESS: return clientSettings.vlesses;
  778. case Protocols.TROJAN: return clientSettings.trojans;
  779. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  780. default: return null;
  781. }
  782. },
  783. getClientId(protocol, client) {
  784. switch (protocol) {
  785. case Protocols.TROJAN: return client.password;
  786. case Protocols.SHADOWSOCKS: return client.email;
  787. default: return client.id;
  788. }
  789. },
  790. checkFallback(dbInbound) {
  791. newDbInbound = new DBInbound(dbInbound);
  792. if (dbInbound.listen.startsWith("@")){
  793. rootInbound = this.inbounds.find((i) =>
  794. i.tls &&
  795. ['trojan','vless'].includes(i.protocol) &&
  796. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  797. );
  798. if (rootInbound) {
  799. newDbInbound.listen = rootInbound.listen;
  800. newDbInbound.port = rootInbound.port;
  801. newInbound = newDbInbound.toInbound();
  802. newInbound.stream.security = 'tls';
  803. newInbound.stream.tls = rootInbound.stream.tls;
  804. newDbInbound.streamSettings = newInbound.stream.toString();
  805. }
  806. }
  807. return newDbInbound;
  808. },
  809. showQrcode(dbInbound, clientIndex) {
  810. newDbInbound = this.checkFallback(dbInbound);
  811. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, clientIndex);
  812. },
  813. showInfo(dbInbound, index) {
  814. newDbInbound = this.checkFallback(dbInbound);
  815. infoModal.show(newDbInbound, index);
  816. },
  817. switchEnable(dbInboundId) {
  818. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  819. this.submit(`/panel/inbound/update/${dbInboundId}`, dbInbound);
  820. },
  821. async switchEnableClient(dbInboundId, client) {
  822. this.loading()
  823. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  824. inbound = dbInbound.toInbound();
  825. clients = this.getClients(dbInbound.protocol, inbound.settings);
  826. index = this.findIndexOfClient(clients, client);
  827. clients[index].enable = !clients[index].enable;
  828. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  829. await this.updateClient(clients[index], dbInboundId, clientId);
  830. this.loading(false);
  831. },
  832. async submit(url, data) {
  833. const msg = await HttpUtil.postWithModal(url, data);
  834. if (msg.success) {
  835. await this.getDBInbounds();
  836. }
  837. },
  838. getInboundClients(dbInbound) {
  839. if (dbInbound.protocol == Protocols.VLESS) {
  840. return dbInbound.toInbound().settings.vlesses;
  841. } else if (dbInbound.protocol == Protocols.VMESS) {
  842. return dbInbound.toInbound().settings.vmesses;
  843. } else if (dbInbound.protocol == Protocols.TROJAN) {
  844. return dbInbound.toInbound().settings.trojans;
  845. } else if (dbInbound.protocol == Protocols.SHADOWSOCKS) {
  846. return dbInbound.toInbound().settings.shadowsockses;
  847. }
  848. },
  849. resetClientTraffic(client, dbInboundId) {
  850. this.$confirm({
  851. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  852. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  853. class: themeSwitcher.darkCardClass,
  854. okText: '{{ i18n "reset"}}',
  855. cancelText: '{{ i18n "cancel"}}',
  856. onOk: () => this.submit('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + client.email),
  857. })
  858. },
  859. resetAllTraffic() {
  860. this.$confirm({
  861. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  862. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  863. class: themeSwitcher.darkCardClass,
  864. okText: '{{ i18n "reset"}}',
  865. cancelText: '{{ i18n "cancel"}}',
  866. onOk: () => this.submit('/panel/inbound/resetAllTraffics'),
  867. });
  868. },
  869. resetAllClientTraffics(dbInboundId) {
  870. this.$confirm({
  871. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  872. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  873. class: themeSwitcher.darkCardClass,
  874. okText: '{{ i18n "reset"}}',
  875. cancelText: '{{ i18n "cancel"}}',
  876. onOk: () => this.submit('/panel/inbound/resetAllClientTraffics/' + dbInboundId),
  877. })
  878. },
  879. delDepletedClients(dbInboundId) {
  880. this.$confirm({
  881. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  882. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  883. class: themeSwitcher.darkCardClass,
  884. okText: '{{ i18n "reset"}}',
  885. cancelText: '{{ i18n "cancel"}}',
  886. onOk: () => this.submit('/panel/inbound/delDepletedClients/' + dbInboundId),
  887. })
  888. },
  889. isExpiry(dbInbound, index) {
  890. return dbInbound.toInbound().isExpiry(index)
  891. },
  892. getUpStats(dbInbound, email) {
  893. if (email.length == 0) return 0
  894. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  895. return clientStats ? clientStats.up : 0
  896. },
  897. getDownStats(dbInbound, email) {
  898. if (email.length == 0) return 0
  899. clientStats = dbInbound.clientStats.find(stats => stats.email === email)
  900. return clientStats ? clientStats.down : 0
  901. },
  902. statsColor(dbInbound, email) {
  903. if(email.length == 0) return 'blue';
  904. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  905. return usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  906. },
  907. isClientEnabled(dbInbound, email) {
  908. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
  909. return clientStats ? clientStats['enable'] : true
  910. },
  911. isRemovable(dbInbound_id) {
  912. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInbound_id)).length > 1
  913. },
  914. inboundLinks(dbInboundId) {
  915. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  916. newDbInbound = this.checkFallback(dbInbound);
  917. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks, newDbInbound.remark);
  918. },
  919. exportAllLinks() {
  920. let copyText = '';
  921. for (const dbInbound of this.dbInbounds) {
  922. copyText += dbInbound.genInboundLinks
  923. }
  924. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText, 'All-Inbounds');
  925. },
  926. async startDataRefreshLoop() {
  927. while (this.isRefreshEnabled) {
  928. try {
  929. await this.getDBInbounds();
  930. } catch (e) {
  931. console.error(e);
  932. }
  933. await PromiseUtil.sleep(this.refreshInterval);
  934. }
  935. },
  936. toggleRefresh() {
  937. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  938. if (this.isRefreshEnabled) {
  939. this.startDataRefreshLoop();
  940. }
  941. },
  942. changeRefreshInterval() {
  943. localStorage.setItem("refreshInterval", this.refreshInterval);
  944. },
  945. async manualRefresh() {
  946. if (!this.refreshing) {
  947. this.spinning = true;
  948. await this.getDBInbounds();
  949. this.spinning = false;
  950. }
  951. },
  952. },
  953. watch: {
  954. searchKey: debounce(function (newVal) {
  955. this.searchInbounds(newVal);
  956. }, 500)
  957. },
  958. mounted() {
  959. this.loading();
  960. this.getDefaultSettings();
  961. if (this.isRefreshEnabled) {
  962. this.startDataRefreshLoop();
  963. }
  964. else {
  965. this.getDBInbounds();
  966. }
  967. this.loading(false);
  968. },
  969. computed: {
  970. total() {
  971. let down = 0, up = 0;
  972. let clients = 0, deactive = [], depleted = [], expiring = [];
  973. this.dbInbounds.forEach(dbInbound => {
  974. down += dbInbound.down;
  975. up += dbInbound.up;
  976. if (this.clientCount[dbInbound.id]) {
  977. clients += this.clientCount[dbInbound.id].clients;
  978. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  979. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  980. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  981. }
  982. });
  983. return {
  984. down: down,
  985. up: up,
  986. clients: clients,
  987. deactive: deactive,
  988. depleted: depleted,
  989. expiring: expiring,
  990. };
  991. }
  992. },
  993. });
  994. </script>
  995. {{template "inboundModal"}}
  996. {{template "promptModal"}}
  997. {{template "qrcodeModal"}}
  998. {{template "textModal"}}
  999. {{template "inboundInfoModal"}}
  1000. {{template "clientsModal"}}
  1001. {{template "clientsBulkModal"}}
  1002. </body>
  1003. </html>